package com.guchenbo.example.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author guchenbo
 * @date 2024/12/13
 */
public class TestThreadPoolShutdown {

    public static void main(String[] args) {
//        noInterruptShutdown();

        interruptShutdown();
    }

  static   void noInterruptShutdown() {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 3; i++) {
            executorService.submit(() -> {
               while (true){}
            });
        }
        executorService.shutdownNow();
    }
    static   void interruptShutdown() {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 3; i++) {
            executorService.submit(() -> {
                    while (!Thread.interrupted()) {
                    }
                System.out.println("interruptShutdown");
            });
        }
        executorService.shutdownNow();
    }
}
